<?php
/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2018/3/23
 * Time: 下午4:30
 */
?>
<!DOCTYPE html>
<html>
<head>
    <!--[if lt IE 7]>
    <div class="ie6_error">还在用<strong>漏洞百出的IE6浏览器</strong>么？为了您的网络安全，请升级浏览器 <a target="_blank"
                                                                               href="http://browsehappy.com">立即升级</a>
    </div>
    <![endif]-->

    <meta charset="utf-8">
    <title>首页-文具1号</title>
    <meta name="description"
          content="文具1号作为上海办公用品供货商公司,专为世界500强企业及SOHO办公族提供网上商城一站式办公耗材批发及采购服务,一站式选购办公日用文具用品,厂家直销,好货又便宜【阳光采购就上文具1号 阳光价格 老板放心 品质保障 员工省力】"/>
    <meta name="keywords" content="办公用品,办公文具,办公文具网站,文具网站,办公用品网,文具采购网,金万年"/>
    <meta name="copyright" content="上海易推信息科技有限公司"/>
    <meta name="renderer" content="webkit">
    <base href="<?php echo base_url(); ?>"/>
    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" type="text/css" href="public/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/cost-center.css"/>

    <!--[if lte IE 9]>
    <script type="text/javascript" src="public/js/html5shiv-printshiv-3.js"></script>
    <![endif]-->
</head>
<body>
<div class="bg">
    <!--common - head -->
    <?php $this->load->view('common/header.php'); ?>
    <!--common - head end-->

    <div class="container mt20 bg-padding-inside">
        <div class="cost-center-container w1200">
            <div class="cost-center-box-wrapper">
                
                <!--red-->
                <div class="cost-center-box cost-center">
                    <div class="top-box">
                        <div class="icon bg-icon_creat_cbzx"></div>
                        <div class="cont">
                            <p class="tit text-ellipsis">
                                创建成本中心
                                <a href="<?php echo base_url('cost_center/cost_center_present'); ?>"
                                   class="about bg-btn_why">关于</a>
                            </p>
                            <p class="intro">
                                管理第一步，直接创建部门或分公司，达到成本的有效管控
                            </p>
                        </div>
                        <div class="btn-create-wrapper">
                            <?php if (isset($customer_info)): ?>
                                <?php if ($customer_info['identity'] == 1) { ?>
                                    <a href="<?php echo base_url('cost_center/create_cost_center_index'); ?>"
                                       class="btn-create btn-create-red"> +
                                        创建成本中心</a>
                                <?php } else { ?>
                                    <!--灰色状态 ↓ -->
                                    <a href="javascript:;" class="btn-create btn-create-red btn-create-gray"> +
                                        创建成本中心</a>
                                <?php } ?>
                            <?php else: ?>
                                <a href="" onmousedown=" window.open('<?php echo $this->config->item("shop_url") . "mMLogin.html" ?>')" class="btn-create btn-create-red"> + 创建成本中心</a>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="btm-box">
                        <div class="tittle-box">
                            <a href="<?php echo base_url('cost_center/create_cost_center_index'); ?>"
                               class="btn-add-icon bg-btn_add_red_n"></a>
                            <!--灰色状态 ↓ -->
                            <!--<a href="javascript:;" class="btn-add-icon bg-btn_add_red_n btn-gray"></a>-->
                            <span class="tittle">成本中心</span>
                            <a href="<?php echo base_url('cost_center/cost_center_index'); ?>"
                               class="btn-refresh bg-btn_refresh_n cost_center"></a>
                        </div>
                        <div class="input-box">
                            <form method="get">
                            <input type="text" class="search-input" name="cost_center" value="<?php if(isset($_GET['cost_center'])):?><?=$_GET['cost_center']?><?php endif;?>" placeholder="在当前条件下搜索">
                            <input type="hidden" name="manager" value="<?php if(isset($_GET['manager'])):?><?=$_GET['manager']?><?php endif;?>">
                            <input type="hidden" name="user" value="<?php if(isset($_GET['user'])):?><?=$_GET['user']?><?php endif;?>">
                            </form>
                            <a href="javascript:;" class="btn-search bg-icon_search_grey" style="cursor:default;"></a>
                        </div>
                        <div class="cont-box" id="cost_center_list">
                            <?php if (isset($cost_center) && count($cost_center)): ?>
                                <?php foreach ($cost_center as $ma): ?>
                                    <a href="javascript:;" data-const_center_id="<?php echo $ma['id'] ?>" class="cont-box-item cost_center_li <?php if ($customer_info['identity'] == 1): ?>cont-box-cost-center<?php endif; ?>"> <?php echo $ma['name'] ?></a>
                                <?php endforeach; ?>
                            <?php endif; ?>
                            <?php if (isset($cost_center) && !count($cost_center)): ?>
                                <span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
                <!--blue-->
                <div class="cost-center-box cost-center">
                    <div class="top-box">
                        <div class="icon bg-icon_creat_cbzx"></div>
                        <div class="cont">
                            <p class="tit text-ellipsis">
                                创建管理账号
                                <a href="<?php echo base_url('cost_center/cost_center_manage_present'); ?>"
                                   class="about bg-btn_why">关于</a>
                            </p>
                            <p class="intro">
                                为各个成本中心创建对应管理（manager）账号
                            </p>
                        </div>
                        <div class="btn-create-wrapper">
                            <?php if (isset($customer_info)): ?>
                                <?php if ($customer_info['identity'] == 1) { ?>
                                    <a href="<?php echo base_url('cost_center/create_manager_index'); ?>"
                                       class="btn-create btn-create-blue"> +
                                        创建管理账号</a>
                                <?php } else { ?>
                                    <!--灰色状态 ↓ -->
                                    <a href="javascript:;" class="btn-create btn-create-red btn-create-gray"> +
                                        创建管理账号</a>
                                <?php } ?>
                            <?php else: ?>
                                <a href=""
                                   onmousedown="window.open('<?php echo $this->config->item("shop_url") . "mMLogin.html" ?>')"  class="btn-create btn-create-blue"> + 创建管理账号</a>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="btm-box">
                        <div class="tittle-box">
                            <a href="<?php echo base_url('cost_center/create_manager_index'); ?>"
                               class="btn-add-icon bg-btn_add_red_n"></a>
                            <!--灰色状态 ↓ -->
                            <!--<a href="javascript:;" class="btn-add-icon bg-btn_add_red_n btn-gray"></a>-->
                            <span class="tittle">管理账号</span>
                            <a href="javascript:;" class="btn-refresh bg-btn_refresh_n mamage" ></a>
                        </div>
                        <div class="input-box">
                            <form method="get">
                            <input type="hidden" name="cost_center"  value="<?php if(isset($_GET['cost_center'])):?><?=$_GET['cost_center']?><?php endif;?>">
                            <input type="text" class="search-input" name="manager" value="<?php if(isset($_GET['manager'])):?><?=$_GET['manager']?><?php endif;?>" placeholder="在当前条件下搜索">
                            <input type="hidden" name="user" value="<?php if(isset($_GET['user'])):?><?=$_GET['user']?><?php endif;?>">
                            </form>
                            <a href="javascript:;" class="btn-search bg-icon_search_grey" style="cursor:default;"></a>
                        </div>
                        <div class="cont-box" id="manager_list">
                            <?php if (isset($manage) && count($manage)): ?>
                                <?php foreach ($manage as $ma): ?>
                                    <a href="javascript:;" data-id="<?php echo $ma['id'] ?>"
                                       class="cont-box-item manager_li <?php if ($customer_info['identity'] == 1): ?>cont-box-manager<?php endif; ?>"> <?php echo $ma['username'] ?></a>
                                <?php endforeach; ?>
                            <?php endif; ?>
                            <?php if (isset($manage) && !count($manage)): ?>
                                <span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
               
                <!--yellow-->
                <div class="cost-center-box cost-center">
                    <div class="top-box">
                        <div class="icon bg-icon_creat_cbzx"></div>
                        <div class="cont">
                            <p class="tit text-ellipsis">
                                创建用户账号
                                <a href="<?php echo base_url('cost_center/cost_center_user_present'); ?>"
                                   class="about bg-btn_why">关于</a>
                            </p>
                            <p class="intro" style="overflow: visible;">
                                创建用户(user)账号，设置账号基本信息，额度、预算和指定商品进行办公用品采购
                            </p>
                        </div>
                        <div class="btn-create-wrapper">
                            <?php if (isset($customer_info)): ?>
                                <a href="<?php echo base_url('cost_center/create_user_index'); ?>"
                                   class="btn-create btn-create-yellow"> + 创建用户账号</a>
                            <?php else: ?>
                                <a href="" id="login" onmousedown=" window.open('<?php echo $this->config->item("shop_url") . "mMLogin.html" ?>')"     class="btn-create btn-create-yellow"> + 创建用户账号</a>
                            <?php endif; ?>
                            <!--灰色状态 ↓ -->
                            <!--<a href="javascript:;" class="btn-create btn-create-red btn-create-gray"> + 创建成本中心</a>-->
                        </div>
                    </div>
                    <div class="btm-box">
                        <div class="tittle-box">

                            <a href="<?php echo base_url('cost_center/create_user_index'); ?>"
                               class="btn-add-icon bg-btn_add_red_n"></a>
                            <!--灰色状态 ↓ -->
                            <!--<a href="javascript:;" class="btn-add-icon bg-btn_add_red_n btn-gray"></a>-->
                            <span class="tittle">用户账号</span>
                            <a href="javascript:;" class="btn-refresh bg-btn_refresh_n"></a>

                        </div>
                        <div class="input-box">
                            <form method="get">
                            <input type="hidden" name="cost_center" value="<?php if(isset($_GET['cost_center'])):?><?=$_GET['cost_center']?><?php endif;?>">
                             <input type="hidden" name="manager" value="<?php if(isset($_GET['manager'])):?><?=$_GET['manager']?><?php endif;?>">
                            <input type="text" class="search-input" name="user" value="<?php if(isset($_GET['user'])):?><?=$_GET['user']?><?php endif;?>" placeholder="在当前条件下搜索">
                            </form>
                            <a href="javascript:;" class="btn-search bg-icon_search_grey" style="cursor:default;"></a>
                        </div>
                        <div class="cont-box" id="user_list">


                                <?php if (isset($manage) && count($user)): ?>
                                <?php foreach ($user as $us): ?>
                                    <a href="javascript:;" data-id="<?php echo $us['id'] ?>"
                                       class="cont-box-item user_li cont-box-user"> <?php echo $us['username'] ?></a>
                                <?php endforeach; ?>
                                <?php endif; ?>
                            <?php if (isset($user) && !count($user)): ?>
                                <span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <?php $this->load->view('common/bottom.php'); ?>
</div>

<script type="text/javascript" src="public/js/jquery.min.js"></script>
<script type="text/javascript" src="public/js/index.js"></script>
<script type="text/javascript" src="public/js/owl.carousel.min.js"></script>
<script type="text/javascript">

    $(function () {
        $(".cost_center_li").live("click", function () {
            $(this).addClass('color-red');
            $(this).siblings().removeClass('color-red');

            var const_center_id = $(this).attr('data-const_center_id');
            query_manager_list({'cost_center_id': const_center_id}, 1);
        });
        $(".manager_li").live("click", function () {
            $(this).addClass('color-blue');
            $(this).siblings().removeClass('color-blue');
            var parent_id = $(this).attr('data-id');
            query_user_list({'parent_id': parent_id});
        });
        $(".cont-box-manager").live("dblclick", function () {
            var parent_id = $(this).attr('data-id');
            location.href = '<?php echo base_url()?>cost_center/manager_user_edit?id=' + parent_id;
        });
        $(".cont-box-user").live("dblclick", function () {
            var parent_id = $(this).attr('data-id');
            location.href = '<?php echo base_url()?>cost_center/manager_user_edit?id=' + parent_id;
        });
        $(".cont-box-cost-center").live("dblclick", function () {
            var cost_center_id = $(this).attr('data-const_center_id');
            location.href = '<?php echo base_url()?>cost_center/update_cost_center_index?cost_center_id=' + cost_center_id;
        });

        $('#cost_center_search').bind('keypress', function (event) {

            if (event.keyCode == "13") {
                var name = $('#cost_center_search').val();
                query_cost_center_list({'name': name}, 1);
            }

        });

        $('#manager_search').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                var username = $('#manager_search').val();
                var cost_center_id = $("#cost_center_list").find(".color-red").attr('data-const_center_id');
                query_manager_list({'cost_center_id': cost_center_id, 'username': username}, 1)
            }

        });

        $('#user_search').bind('keypress', function (event) {

            if (event.keyCode == "13") {
                var username = $('#user_search').val();
                var parent_id = $("#manager_list").find(".color-blue").attr('data-id');
                if (!parent_id) {
                    layer.alert("请先选择管理账号");
                    return;
                }
                query_user_list({'parent_id': parent_id, 'username': username})
            }

        });

        //管理账号处刷新
        $('.mamage').click(function () {
            $('.manager_li').find('.color-blue').removeClass('color-blue');
            var cost_center_id = $("#cost_center_list").find(".color-red").attr('data-const_center_id');
            consloe.log(666);
            $.ajax({
                type: "POST",
                url: "cost_center/query_manager_list",
                data: {'cost_center_id': cost_center_id},
                dataType: "json",
                async: true,
                success: function (data) {
                    var tr = data.data;
                    if (data.code == 0) {
                        if (tr[1] != '') {
                            var html = '';
                            $(tr[1]).each(function (key, val) {
                                if (tr[3] != 1) {
                                    html += '<a href="javascript:;" data-id =" ' + val.id + '"  class="cont-box-item manager_li" >' + val.username + '</a>';
                                } else {
                                    html += '<a href="javascript:;" data-id =" ' + val.id + '"  class="cont-box-item manager_li cont-box-manager" >' + val.username + '</a>';
                                }
                            });
                            $("#manager_list").html(html);
                            if (tr[2] != '') {
                                var str = '';
                                for (ke in tr[2]) {
                                    if (tr[2][ke] != '') {
                                        // console.log(tr[2][ke]['username']);
                                        str += '<a href="javascript:;"  data-id ="" class="cont-box-item user_li cont-box-user">' + tr[2][ke]['username'] + '</a>';
                                    }
                                }
                                $("#user_list").html(str);
                            }else{
                                $("#user_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                            }

                            // if (flag == 1) {
                            //     // 默认第一个选中
                            //     $("#manager_list").find('a').first().click();
                            // }

                        } else {
                            $("#manager_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                            $("#user_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                        }
                    }
                }
            });
        });
    });

    function query_cost_center_list(data) {

        $.ajax({
            type: "POST",
            url: "cost_center/cost_center_list",
            data: data,
            dataType: "json",
            async: true,
            success: function (data) {
                // console.log(data);
                if (data.code == 0) {
                    if (data.data) {
                        var html = '';
                        $(data.data).each(function (key, val) {
                            if (data.identity != 1) {
                                html += '<a href="javascript:;" data-const_center_id = "' + val.id + '" class="cont-box-item cost_center_li">' + val.name + '</a>';
                            } else {
                                html += '<a href="javascript:;" data-const_center_id = "' + val.id + '" class="cont-box-item cost_center_li cont-box-cost-center">' + val.name + '</a>';
                            }
                        });
                        $("#cost_center_list").html(html);
                        // if (flag == 1) {
                        //     // 默认第一个选中
                        //     $("#cost_center_list").find('a').first().click();
                        // }
                    } else {
                        $("#cost_center_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                        $("#manager_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                        $("#user_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                    }
                }
            }
        });
    }

    function query_manager_list(data) {
        $.ajax({
            type: "POST",
            url: "cost_center/query_manager_list",
            data: data,
            dataType: "json",
            async: true,
            success: function (data) {
                var tr = data.data;
                if (data.code == 0) {
                    console.log(tr[1]);
                    console.log(tr[2]);
                    var html = '';
                    if (tr[1] != '') {
                        $(tr[1]).each(function (key, val) {
                            if (data.identity != 1) {
                                html += '<a href="javascript:;" data-id =" ' + val.id + '"  class="cont-box-item manager_li" >' + val.username + '</a>';
                            } else {
                                html += '<a href="javascript:;" data-id =" ' + val.id + '"  class="cont-box-item manager_li cont-box-manager" >' + val.username + '</a>';
                            }
                        });
                        $("#manager_list").html(html);
                    }else{
                        $("#manager_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                    }
                    if (tr[2] != '') {
                        var str = '';
                        for (ke in tr[2]) {
                            if (tr[2][ke] != '') {
                                // console.log(tr[2][ke]['username']);
                                str += '<a href="javascript:;"  data-id ="' + tr[2][ke]['id'] + '"  class="cont-box-item  user_li cont-box-user">' + tr[2][ke]['username'] + '</a>';
                            }
                        }
                        $("#user_list").html(str);
                    } else {
                        $("#user_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                    }
                }
            }
        });
    }

    function query_user_list(data) {
        $.ajax({
            type: "POST",
            url: "cost_center/query_user_list",
            data: data,
            dataType: "json",
            async: true,
            success: function (data) {
                // console.log(data);
                if (data.code == 0) {
                    if (data.data != '') {
                        var html = '';
                        $(data.data).each(function (key, val) {
                            html += '<a href="javascript:;" data-id = "' + val.id + '" class="cont-box-item user_li cont-box-user">' + val.username + '</a>';
                        });
                        $("#user_list").html(html);

                    } else {
                        $("#user_list").html('<span class="icon-none bg-img_nonedate"></span><p class="icon-none-p">暂时木有数据呀</p>');
                    }
                }
            }
        });
    }
    $('.#login').click(function(){
        window.location.href('<?php echo $this->config->item("shop_url") . "mMLogin.html" ?>');
    })

</script>
</body>
</html>
